package com.wjh.kt_activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjh.kt_activity.service.CouponInfoService;
import com.wjh.kt_activity.service.CouponUseService;
import com.wjh.kt_vod.model.activity.CouponInfo;
import com.wjh.kt_vod.model.activity.CouponUse;
import com.wjh.kt_vod.result.Result;
import com.wjh.kt_vod.vo.activity.CouponUseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author Wang_Junhong
 * @since 2022-07-16
 */

@Api(tags = "优惠券管理")
@RestController
@RequestMapping("/admin/activity/couponInfo")
public class CouponInfoController {

    @Autowired
    private CouponUseService couponUseService;

    @Autowired
    private CouponInfoService couponInfoService;

    @ApiOperation(value = "获取优惠券")
    @GetMapping("get/{id}")
    public Result get(@PathVariable String id) {
        CouponInfo couponInfo = couponInfoService.getById(id);
        return Result.ok(couponInfo);
    }

    @ApiOperation(value = "新增优惠券")
    @PostMapping("save")
    public Result save(@RequestBody CouponInfo couponInfo) {
        couponInfoService.save(couponInfo);
        return Result.ok();
    }

    @ApiOperation(value = "修改优惠券")
    @PutMapping("update")
    public Result updateById(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateById(couponInfo);
        return Result.ok();
    }

    @ApiOperation(value = "删除优惠券")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id) {
        couponInfoService.removeById(id);
        return Result.ok();
    }

    @ApiOperation(value = "根据id列表删除优惠券")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<String> idList) {
        couponInfoService.removeByIds(idList);
        return Result.ok();
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(@ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page
            , @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable("limit") Long limit) {

        Page<CouponInfo> couponInfoPage = new Page<>(page, limit);
        IPage<CouponInfo> couponInfoIPageModel = couponInfoService.page(couponInfoPage);
        return Result.ok(couponInfoIPageModel);
    }

    @ApiOperation(value = "获取分页列表条件")
    @GetMapping("couponUse/{page}/{limit}")
    public Result index(@ApiParam(name = "page", value = "当前页", required = true) @PathVariable("page") Long page
            , @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable("limit") Long limit
            , @ApiParam(name = "couponUseVo", value = "查询对象", required = false) CouponUseQueryVo couponUseQueryVo) {

        Page<CouponUse> couponUsePage = new Page<>(page, limit);
        IPage<CouponUse> couponUseInfoPage = couponUseService.getCouponUseInfoPage(couponUsePage, couponUseQueryVo);
        return Result.ok(couponUseInfoPage);
    }


}
